local osXuechang = fk.CreateSkill {
  name = "md__xuechang"
}

Fk:loadTranslationTable{
  ["md__xuechang"] = "血偿",
  [":md__xuechang"] = "出牌阶段限两次，你可以摸一张牌并与一名角色拼点，若你赢，你获得其至多两张牌，若其中有装备牌，" ..
  "则你视为对其使用一张【杀】；若你没赢，你受到其造成的1点伤害，你下次对其造成的伤害+1。",

  ["#md__xuechang"] = "血偿:与一名角色拼点，若你赢获得其牌，没赢你受到其伤害",
  ["#md__xuechang_damage"] = "血偿",

  ["$md__xuechang1"] = "风尘难掩忠魂血，杀尽宦祸不得偿！",
  ["$md__xuechang2"] = "霜刃绚练，血舞婆娑。",
}

osXuechang:addEffect("active", {
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  prompt = "#md__xuechang",
  times = function (self, player)
    return 1 - player:usedSkillTimes(osXuechang.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return not player:isKongcheng() and player:usedSkillTimes(osXuechang.name, Player.HistoryPhase) <= 1
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and player:canPindian(to_select) and to_select ~= player
  end,
  on_use = function(self, room, effect)
    ---@type string
    local skillName = osXuechang.name
    local player = effect.from
    local target = effect.tos[1]
    player:drawCards(1, osXuechang.name)
    local pindian = player:pindian({target}, skillName)
    if pindian.results[target].winner == player then
      if target:isNude() then return false end
      local cids = room:askToChooseCards(player, {
        min = 1,
        max = 2,
        target = target,
        flag = "he",
        skill_name = skillName
      })
      room:obtainCard(player, cids, false, fk.ReasonPrey, player, skillName)
      local judge = false
      for _, cid in ipairs(cids) do
        -- 获取当前卡牌对象
        local card = Fk:getCardById(cid)
        -- 判断是否为装备牌
        if card.type == Card.TypeEquip then
          judge = true
        end
      end
      if judge then
        room:useVirtualCard("slash", nil, player, target, skillName, true)
        judge = false
      end
    else
      room:damage{
        from = target,
        to = player,
        damage = 1,
        skillName = skillName,
      }
      room:addPlayerMark(player, "_md__xuechang+" .. target.id, 1)
    end
  end,
})

osXuechang:addEffect(fk.DamageCaused, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("_md__xuechang+" .. data.to.id) > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local damageBuff = player:getMark("_md__xuechang+" .. data.to.id)
    player.room:setPlayerMark(player, "_md__xuechang+" .. data.to.id, 0)
    data:changeDamage(damageBuff)
  end,
})

return osXuechang
